/*
 * Copyright 2009 Nordic Consulting & Development Company
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package pl.ncdc.web.login.client.ui;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.Label;


/**
 * Displays notification messages and busy indicator.
 * <p>
 * Created on Apr 17, 2008
 *
 * @author hshsce
 * @version $Id: NotificationAreaWidget.java 186 2009-04-09 12:33:05Z hshsce $
 */
public class NotificationAreaWidget extends Composite {

	public static final String WIDGET_ID = "ncdc-web-login-NotificationAreaWidget";

	public enum State {

		CLEAR,

		NOTIFICATION,

		BUSY
	}

	private final DeckPanel m_panel = new DeckPanel();
	{
		m_panel.setAnimationEnabled(true);
	}

	private State m_state = State.CLEAR;

	private final Label m_msgLabel;

	public NotificationAreaWidget() {
		Label msgLabel = null;
		for (final State state : State.values()) {
			final Label label = new Label();
			if (state == State.NOTIFICATION) {
				msgLabel = label;
			}
			label.setStyleName(state.name());
			m_panel.add(label);
		}
		m_msgLabel = msgLabel;
		initWidget(m_panel);
		setStyleName(WIDGET_ID);
	}

	public void setMessage(final String message) {
		m_msgLabel.setText(message);
	}

	public String getMessage() {
		return m_msgLabel.getText();
	}

	public void setState(final State state) {
		if (state == null) {
			throw new IllegalArgumentException("state cannot be null");
		}
		m_state = state;
		m_panel.showWidget(state.ordinal());
	}

	/**
	 * @return the state
	 */
	public State getState() {
		return m_state;
	}

}
